{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Title: #Minimum Number of Operations to Convert Time"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Difficulty: #Easy"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Category Title: #Algorithms"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Tag Slug: #greedy #string"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Name Translated: #贪心 #字符串"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solution Name: convertTime"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Title: #转化时间需要的最少操作数"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Translated Content:\n",
    "<p>给你两个字符串 <code>current</code> 和 <code>correct</code> ，表示两个 <strong>24 小时制时间</strong> 。</p>\n",
    "\n",
    "<p><strong>24 小时制时间</strong> 按 <code>\"HH:MM\"</code> 进行格式化，其中 <code>HH</code> 在 <code>00</code> 和 <code>23</code> 之间，而 <code>MM</code> 在 <code>00</code> 和 <code>59</code> 之间。最早的 24 小时制时间为 <code>00:00</code> ，最晚的是 <code>23:59</code> 。</p>\n",
    "\n",
    "<p>在一步操作中，你可以将 <code>current</code> 这个时间增加 <code>1</code>、<code>5</code>、<code>15</code> 或 <code>60</code> 分钟。你可以执行这一操作 <strong>任意</strong> 次数。</p>\n",
    "\n",
    "<p>返回将&nbsp;<code>current</code><em> </em>转化为<em> </em><code>correct</code> 需要的 <strong>最少操作数</strong> 。</p>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>示例 1：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>current = \"02:30\", correct = \"04:35\"\n",
    "<strong>输出：</strong>3\n",
    "<strong>解释：\n",
    "</strong>可以按下述 3 步操作将 current 转换为 correct ：\n",
    "- 为 current 加 60 分钟，current 变为 \"03:30\" 。\n",
    "- 为 current 加 60 分钟，current 变为 \"04:30\" 。 \n",
    "- 为 current 加 5 分钟，current 变为 \"04:35\" 。\n",
    "可以证明，无法用少于 3 步操作将 current 转化为 correct 。</pre>\n",
    "\n",
    "<p><strong>示例 2：</strong></p>\n",
    "\n",
    "<pre><strong>输入：</strong>current = \"11:00\", correct = \"11:01\"\n",
    "<strong>输出：</strong>1\n",
    "<strong>解释：</strong>只需要为 current 加一分钟，所以最小操作数是 1 。\n",
    "</pre>\n",
    "\n",
    "<p>&nbsp;</p>\n",
    "\n",
    "<p><strong>提示：</strong></p>\n",
    "\n",
    "<ul>\n",
    "\t<li><code>current</code> 和 <code>correct</code> 都符合 <code>\"HH:MM\"</code> 格式</li>\n",
    "\t<li><code>current &lt;= correct</code></li>\n",
    "</ul>\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Description: [minimum-number-of-operations-to-convert-time](https://leetcode.cn/problems/minimum-number-of-operations-to-convert-time/description/)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Solutions: [minimum-number-of-operations-to-convert-time](https://leetcode.cn/problems/minimum-number-of-operations-to-convert-time/solutions/)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "test_cases = ['\"02:30\"\\n\"04:35\"', '\"11:00\"\\n\"11:01\"']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        dif1 = int(correct[0:2])*60 + int(correct[3:])\n",
    "        dif2 = int(current[0:2])*60 + int(current[3:])\n",
    "        dif_time = dif1 - dif2\n",
    "\n",
    "        cnt = 0\n",
    "        for x in [60,15,5,1]:\n",
    "            cnt += dif_time // x\n",
    "            dif_time %= x\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        if current == correct:\n",
    "            return 0\n",
    "        def getMin(aStr):\n",
    "            h, m = aStr.split(\":\")\n",
    "            return int(h) * 60 + int(m)\n",
    "        c, t = getMin(current), getMin(correct)\n",
    "        d = t - c\n",
    "        ret = 0\n",
    "        ret = ret + d // 60\n",
    "        d = d % 60\n",
    "        ret = ret + d // 15\n",
    "        d = d % 15\n",
    "        ret = ret + d // 5\n",
    "        d = d % 5\n",
    "        ret += d\n",
    "        return ret"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        curhh = int(current[0:2])\n",
    "        curmm = int(current[3:5])\n",
    "        corhh = int(correct[0:2])\n",
    "        cormm = int(correct[3:5])\n",
    "        res = corhh - curhh\n",
    "        tmp = cormm - curmm\n",
    "        if curmm > cormm :\n",
    "            res -= 1\n",
    "            tmp += 60\n",
    "        res = res + tmp // 15 + (tmp % 15) // 5 + (tmp % 15) % 5\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        hour1, min1 = map(int, current.split(':'))\n",
    "        hour2, min2 = map(int, correct.split(':'))\n",
    "        \n",
    "        # 将小时和分钟转换为总分钟数\n",
    "        total_min1 = hour1 * 60 + min1\n",
    "        total_min2 = hour2 * 60 + min2\n",
    "        \n",
    "        time_difference = abs(total_min2 - total_min1)\n",
    "        \n",
    "        n = 0\n",
    "        while time_difference >= 60:\n",
    "            time_difference -= 60\n",
    "            n += 1\n",
    "        \n",
    "        while time_difference >= 15:\n",
    "            time_difference -= 15\n",
    "            n += 1\n",
    "        \n",
    "        while time_difference >= 5:\n",
    "            time_difference -= 5\n",
    "            n += 1\n",
    "        \n",
    "        n += time_difference\n",
    "        \n",
    "        return n\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        h, m = map(int, current.split(':'))\n",
    "        h2, m2 = map(int, correct.split(':'))\n",
    "        d = (h2 - h) * 60 + m2 - m\n",
    "        ret = d // 60 \n",
    "        d %= 60\n",
    "        ret += d // 15\n",
    "        d %= 15\n",
    "        ret += d // 5\n",
    "        d %= 5\n",
    "        return ret + d"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        # 计算差距时间分钟数\n",
    "        length = int(correct.split(\":\")[0]) * 60 + int(correct.split(\":\")[1]) - int(current.split(\":\")[0]) * 60 - int(current.split(\":\")[1])\n",
    "        tags = [60, 15, 5, 1]\n",
    "        ans = 0\n",
    "        for tag in tags:\n",
    "            if length >= tag:\n",
    "                ans += length // tag\n",
    "                length = length % tag\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        cur1=int(current[:2])*60+int(current[3:])\n",
    "        cur2=int(correct[:2])*60+int(correct[3:])\n",
    "        target=cur2-cur1\n",
    "        x=[60,15,5,1]\n",
    "        cnt=0\n",
    "        for i in range(4):\n",
    "            if target==0: return cnt\n",
    "            if target>=x[i]:\n",
    "                cnt+=target//x[i]\n",
    "                target=target%x[i]\n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        cor = list(map(int,correct.split(\":\")))\n",
    "        cur = list(map(int,current.split(\":\")))\n",
    "        minus = cor[0]*60+cor[1]-(cur[0]*60+cur[1])\n",
    "        count = 0\n",
    "        while minus>0:\n",
    "            if minus>=60:\n",
    "                minus -= 60\n",
    "            elif minus>=15:\n",
    "                minus -= 15\n",
    "            elif minus>=5:\n",
    "                minus -= 5\n",
    "            else:\n",
    "                minus -= 1\n",
    "            count += 1\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "  def convertTime(self, current: str, correct: str) -> int:\n",
    "      current = self.convertMins(current)\n",
    "      correct = self.convertMins(correct)\n",
    "      all_time = correct - current\n",
    "      count = 0\n",
    "      for t in [60, 15, 5, 1]:\n",
    "          count += all_time // t\n",
    "          all_time %= t\n",
    "      return count\n",
    "  def convertMins(self, time:str)->int:\n",
    "      hours = int(time[:2])\n",
    "      mins = int(time[3:])\n",
    "      total_mins = hours * 60 + mins\n",
    "      return total_mins"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        temp1=current.split(':')\n",
    "        temp2=correct.split(':')\n",
    "        diff1=60*int(temp2[0])-60*int(temp1[0])+int(temp2[1])-int(temp1[1])\n",
    "        #print(temp1,temp2)\n",
    "        res=0\n",
    "        for x in [60,15,5,1]:\n",
    "             res+=diff1//x\n",
    "             diff1=diff1%x\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        count=0\n",
    "        cr=[int(i) for i in current.split(\":\")]\n",
    "        ct=[int(i) for i in correct.split(\":\")]\n",
    "        count+=ct[0]-cr[0]\n",
    "        dmin=ct[1]-cr[1]\n",
    "        print(count,dmin)\n",
    "        if dmin<0:\n",
    "            count-=1\n",
    "            dmin=dmin+60\n",
    "        #print(count,dmin)\n",
    "        count+=dmin//15\n",
    "        count+=dmin%15//5\n",
    "        count+=dmin%15%5\n",
    "        return count\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        HM_1 = int(current[:2]) * 60 + int(current[3:])\n",
    "        HM_2 = int(correct[:2]) * 60 + int(correct[3:])\n",
    "        dis_M = HM_2 - HM_1\n",
    "        use_times = 0\n",
    "        while dis_M >0:\n",
    "            for k in [60,15,5,1]:\n",
    "                if dis_M >=k:\n",
    "                    use_times += int(dis_M / k)\n",
    "                    dis_M = dis_M % k\n",
    "                    break\n",
    "        return use_times"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        \n",
    "        h = int(correct[:2]) - int(current[:2])\n",
    "        m = int(correct[3:]) - int(current[3:])     # 有可能m<0\n",
    "        \n",
    "        x = 60*h + m    # 相差的分钟数\n",
    "        \n",
    "        ans = 0\n",
    "        for base in [60,15,5,1]:    # 从大往小依次考虑\n",
    "            ans += x//base\n",
    "            x %= base\n",
    "            if x==0:\n",
    "                break\n",
    "        \n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        time1 = int(current[:2]) * 60 + int(current[3:])\n",
    "        time2 = int(correct[:2]) * 60 + int(correct[3:])\n",
    "        diff = time2 - time1   # 需要增加的分钟数\n",
    "        res = 0\n",
    "        # 尽可能优先使用增加数值更大的操作\n",
    "        for t in [60, 15, 5, 1]:\n",
    "            res += diff // t\n",
    "            diff %= t\n",
    "        return res\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        HH_1 = int(current.split(':')[0])\n",
    "        MM_1 = int(current.split(':')[1])\n",
    "        HH_2 = int(correct.split(':')[0])\n",
    "        MM_2 = int(correct.split(':')[1])\n",
    "        if MM_2 < MM_1:\n",
    "            MM_2 += 60\n",
    "            HH_2 -= 1\n",
    "        use_times = HH_2 - HH_1\n",
    "        dis_M = MM_2 - MM_1\n",
    "        while dis_M >0:\n",
    "            for k in [60,15,5,1]:\n",
    "                if dis_M >=k:\n",
    "                    use_times += int(dis_M / k)\n",
    "                    dis_M = dis_M % k\n",
    "                    break\n",
    "        return use_times"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        n = abs((int(correct[:2]) - int(current[:2]))*60 + int(correct[-2:]) - int(current[-2:]))\n",
    "        subtract = [60,15, 5, 1]\n",
    "        count = 0\n",
    "        for i in subtract:\n",
    "            if n == 0: break\n",
    "            if n >= i:\n",
    "                count += n // i\n",
    "                n %= i\n",
    "        return count"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        h = (int(correct[:2]) - int(current[:2])) * 60\n",
    "        m = int(correct[-2:]) - int(current[-2:])\n",
    "        tmp = h + m\n",
    "        ans = tmp // 60\n",
    "        tmp %= 60\n",
    "        ans += tmp // 15\n",
    "        tmp %= 15\n",
    "        ans += tmp // 5\n",
    "        tmp %= 5\n",
    "        return ans + tmp"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "  def convertTime(self, current: str, correct: str) -> int:\n",
    "      if current == correct:\n",
    "          return 0\n",
    "      current = self.convertMins(current)\n",
    "      correct = self.convertMins(correct)\n",
    "      all_time = correct - current\n",
    "      count = 0\n",
    "      for t in [60, 15, 5, 1]:\n",
    "          count += all_time // t\n",
    "          all_time %= t\n",
    "      return count\n",
    "  def convertMins(self, time:str)->int:\n",
    "      \n",
    "      hours = int(time[:2])\n",
    "      mins = int(time[3:])\n",
    "      total_mins = hours * 60 + mins\n",
    "      return total_mins"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        current_time = current.split(\":\")\n",
    "        correct_time = correct.split(\":\")\n",
    "\n",
    "        minutes = int(correct_time[1]) - int(current_time[1])\n",
    "        hours = int(correct_time[0]) - int(current_time[0])\n",
    "        \n",
    "        if minutes < 0:\n",
    "            minutes += 60\n",
    "            hours -= 1\n",
    "        \n",
    "        ans = hours\n",
    "        while minutes > 0:\n",
    "            if minutes >= 15:\n",
    "                minutes -= 15\n",
    "            elif minutes >= 5:\n",
    "                minutes -= 5\n",
    "            else:\n",
    "                minutes -= 1\n",
    "            ans += 1\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        time1 = int(current[:2]) * 60 + int(current[3:])\n",
    "        time2 = int(correct[:2]) * 60 + int(correct[3:])\n",
    "        diff = time2 - time1   # 需要增加的分钟数\n",
    "        res = 0\n",
    "        # 尽可能优先使用增加数值更大的操作\n",
    "        for t in [60, 15, 5, 1]:\n",
    "            res += diff // t\n",
    "            diff %= t\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "      if current == correct:\n",
    "        return 0\n",
    "      \n",
    "      _current = [int(x) for x in current.split(\":\")]\n",
    "      _correct = [int(x) for x in correct.split(\":\")]\n",
    "      \n",
    "      _current = _current[0]*60 + _current[1]\n",
    "      _correct = _correct[0]*60 + _correct[1]\n",
    "\n",
    "      mins = _correct - _current\n",
    "\n",
    "      _60min = mins//60\n",
    "      mins = mins%60 \n",
    "\n",
    "      _15min = mins//15\n",
    "      mins = mins%15\n",
    "\n",
    "      _5min = mins//5\n",
    "      mins = mins%5\n",
    "\n",
    "      return _60min + _15min + _5min + mins\n",
    "\n",
    "      # return hr + _15min + _5min + _1min\n",
    "      "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        def to_minutes(s):\n",
    "            return int(s[:2]) * 60 + int(s[3:])\n",
    "        \n",
    "        diff_minutes = to_minutes(correct) - to_minutes(current)\n",
    "        steps = 0\n",
    "        for increment in (60, 15, 5, 1):\n",
    "            steps += (diff_minutes // increment)\n",
    "            diff_minutes %= increment\n",
    "        return steps"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        current,correct=current.split(\":\"),correct.split(\":\")\n",
    "        times=0\n",
    "        need=int(correct[0])*60+int(correct[1])-int(current[0])*60-int(current[1])\n",
    "        while need>0:\n",
    "            if need-60>=0:\n",
    "                need-=60\n",
    "            elif need-15>=0:\n",
    "                need-=15\n",
    "            elif need-5>=0:\n",
    "                need-=5\n",
    "            else:\n",
    "                need-=1\n",
    "            times+=1\n",
    "        return times"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        current = self.to_min(current)\n",
    "        correct = self.to_min(correct)\n",
    "        diff = correct - current\n",
    "        ans = 0\n",
    "        add_time = [60, 15, 5, 1]\n",
    "        for i in range(4):\n",
    "            ans += diff // add_time[i]\n",
    "            diff = diff % add_time[i]\n",
    "        return ans\n",
    "\n",
    "    def to_min(self, t: str):\n",
    "        t = t.split(':')\n",
    "        return int(t[0]) * 60 + int(t[1])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        return (z:=(int(correct[:2])*60+int(correct[3:]))-(int(current[:2])*60+int(current[3:])))//60+z%60//15+z%15//5+z%5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        time1 = int(current[:2]) * 60 + int(current[3:])\n",
    "        time2 = int(correct[:2]) * 60 + int(correct[3:])\n",
    "        diff = time2 - time1   # 需要增加的分钟数\n",
    "        res = 0\n",
    "        # 尽可能优先使用增加数值更大的操作\n",
    "        for t in [60, 15, 5, 1]:\n",
    "            res += diff // t\n",
    "            diff %= t\n",
    "        return res\n",
    "\n",
    "\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        t = (int(correct[:2]) * 60 + int(correct[3:])) - (int(current[:2]) * 60 + int(current[3:]))\n",
    "        ans = 0\n",
    "        for a in [60, 15, 5, 1]:\n",
    "            while t // a != 0:\n",
    "                ans += t // a\n",
    "                t = t - (t // a) * a\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        # 计算相差的分钟数\n",
    "        mins = 0\n",
    "        if correct[:2] >= current[:2] and correct[3:] >= current[3:]:\n",
    "            if correct[3:] >= current[3:]:\n",
    "                mins = 60 * (int(correct[:2]) - int(current[:2])) + (int(correct[3:]) - int(current[3:]))\n",
    "            else: \n",
    "                mins = 60 * (int(correct[:2]) - int(current[:2]) - 1) + (int(correct[3:]) - int(current[3:]) + 60)\n",
    "        else:\n",
    "            mins = 60 * (int(correct[:2]) - int(current[:2])) + (int(correct[3:]) - int(current[3:]))\n",
    "        if mins < 0:\n",
    "            mins += 3600\n",
    "        res = 0\n",
    "        while mins > 0:\n",
    "            res += 1\n",
    "            if mins >= 60:\n",
    "                mins -= 60\n",
    "            elif mins >= 15:\n",
    "                mins -= 15\n",
    "            elif mins >= 5:\n",
    "                mins -= 5\n",
    "            elif mins >= 1:\n",
    "                mins -= 1\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        current,correct=current.split(\":\"),correct.split(\":\")\n",
    "        times=0\n",
    "        need=int(correct[0])*60+int(correct[1])-int(current[0])*60-int(current[1])\n",
    "        while need>0:\n",
    "            if need-60>=0:\n",
    "                need-=60\n",
    "            elif need-15>=0:\n",
    "                need-=15\n",
    "            elif need-5>=0:\n",
    "                need-=5\n",
    "            else:\n",
    "                need-=1\n",
    "            times+=1\n",
    "        return times"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def minuteTime(self,current):\n",
    "        return int(current[0:2])*60+int(current[3:])\n",
    "\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        change=self.minuteTime(correct)-self.minuteTime(current)\n",
    "        res_60=change%60\n",
    "        count_60=int(change/60)\n",
    "        res_15=res_60%15\n",
    "        count_15=int(res_60/15)       \n",
    "        res_5=res_15%5\n",
    "        count_5=int(res_15/5)\n",
    "        return count_5+count_15+count_60+res_5\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        a=int(current[:2])\n",
    "        c=int(current[3:])\n",
    "        b=int(correct[:2])\n",
    "        d=int(correct[3:])\n",
    "        e=d-c+(b-a)*60\n",
    "        f=0\n",
    "        g=0\n",
    "        while e>g:\n",
    "            f=f+1\n",
    "            if g+60<=e:\n",
    "                g=g+60\n",
    "            elif g+15<=e:\n",
    "                g=g+15\n",
    "            elif g+5<=e:\n",
    "                g=g+5\n",
    "            else:\n",
    "                g=g+1\n",
    "        return f"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        cur_set = current.split(\":\")\n",
    "        cor_set = correct.split(\":\")\n",
    "\n",
    "        count_hour = int(cor_set[0]) - int(cur_set[0])\n",
    "\n",
    "        start_min = int(cur_set[1])\n",
    "        end_min = int(cor_set[1])\n",
    "\n",
    "        if start_min > end_min:\n",
    "            count_hour -= 1\n",
    "            end_min += 60\n",
    "\n",
    "        count_min = 0\n",
    "        dif_min = end_min - start_min\n",
    "\n",
    "        while dif_min >= 15:\n",
    "            dif_min -= 15\n",
    "            count_min += 1\n",
    "        while dif_min >= 5:\n",
    "            dif_min -= 5\n",
    "            count_min += 1\n",
    "        while dif_min >= 1:\n",
    "            dif_min -= 1\n",
    "            count_min += 1\n",
    "        return count_hour+count_min"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        t1 = current.split(':')\n",
    "        t1 = int(t1[0]) * 60 + int(t1[1])\n",
    "        t2 = correct.split(':')\n",
    "        t2 = int(t2[0]) * 60 + int(t2[1])\n",
    "        ans = 0\n",
    "        for i in (60, 15, 5, 1):\n",
    "            cnt = (t2 - t1) // i\n",
    "            ans += cnt\n",
    "            t2 -= i * cnt \n",
    "        return ans\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        current = current.split(\":\")\n",
    "        correct = correct.split(\":\")\n",
    "        res = int(correct[0])-int(current[0])\n",
    "        tmp = int(correct[1])-int(current[1])\n",
    "        if tmp<0:\n",
    "            res-=1\n",
    "            tmp+=60\n",
    "        res+=tmp//15\n",
    "        tmp%=15\n",
    "        res+=tmp//5+tmp%5\n",
    "        return res\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        distance = (int(correct.split(':')[0])-int(current.split(':')[0]))*60+(int(correct.split(':')[1])-int(current.split(':')[1]))\n",
    "        fre = 0\n",
    "        while distance >=60:\n",
    "            distance -=60\n",
    "            fre +=1\n",
    "        while distance >=15:\n",
    "            distance -=15\n",
    "            fre +=1\n",
    "        while distance >=5:\n",
    "            distance -=5\n",
    "            fre +=1\n",
    "        while distance >=1:\n",
    "            distance -=1\n",
    "            fre +=1\n",
    "        return fre"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        hour1,min1 = int(current.split(':')[0]),int(current.split(':')[1])\n",
    "        hour2,min2 = int(correct.split(':')[0]), int(correct.split(':')[1])\n",
    "        time = (hour2 - hour1)*60 + min2 - min1\n",
    "        n = 0\n",
    "        while time != 0:\n",
    "            if time >= 60:\n",
    "                time -= 60\n",
    "            elif time >= 15:\n",
    "                time -=15 \n",
    "            elif time >= 5:\n",
    "                time -=5 \n",
    "            elif time >= 1:\n",
    "                time -= 1 \n",
    "            n += 1\n",
    "        return n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        count=0\n",
    "        diff=0\n",
    "        if int(correct[3:5])>=int(current[3:5]):\n",
    "            diff+=(int(correct[0:2])-int(current[0:2]))*60\n",
    "            diff+=int(correct[3:5])-int(current[3:5])\n",
    "        else:\n",
    "            diff+=(int(correct[0:2])-int(current[0:2])-1)*60\n",
    "            diff+=int(correct[3:5])-int(current[3:5])+60\n",
    "        count+=diff//60\n",
    "        diff-=60*(diff//60)\n",
    "        count+=diff//15\n",
    "        diff-=15*(diff//15)\n",
    "        count+=diff//5\n",
    "        diff-=5*(diff//5)\n",
    "        count+=diff\n",
    "        return count\n",
    "        \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        current,correct=current.split(\":\"),correct.split(\":\")\n",
    "        times=0\n",
    "        need=int(correct[0])*60+int(correct[1])-int(current[0])*60-int(current[1])\n",
    "        while need>0:\n",
    "            if need-60>=0:\n",
    "                need-=60\n",
    "            elif need-15>=0:\n",
    "                need-=15\n",
    "            elif need-5>=0:\n",
    "                need-=5\n",
    "            else:\n",
    "                need-=1\n",
    "            times+=1\n",
    "        return times"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        times=0\n",
    "        minute=int(correct[-2::])-int(current[-2::])\n",
    "        if minute>=0:\n",
    "            times+=int(correct[0:2])-int(current[0:2])\n",
    "            times+=int(minute/15)\n",
    "            times+=int((minute%15)/5)\n",
    "            times+=int(minute%5)\n",
    "        else:\n",
    "            minute=minute+60\n",
    "            times+=int(correct[0:2])-int(current[0:2])-1\n",
    "            times+=int(minute/15)\n",
    "            times+=int((minute%15)/5)\n",
    "            times+=int(minute%5)\n",
    "        return times\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        current,correct=current.split(\":\"),correct.split(\":\")\n",
    "        times=0\n",
    "        need=int(correct[0])*60+int(correct[1])-int(current[0])*60-int(current[1])\n",
    "        while need>0:\n",
    "            if need-60>=0:\n",
    "                need-=60\n",
    "            elif need-15>=0:\n",
    "                need-=15\n",
    "            elif need-5>=0:\n",
    "                need-=5\n",
    "            else:\n",
    "                need-=1\n",
    "            times+=1\n",
    "        return times"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        time1 = int(current[:2])*60+int(current[3:])\n",
    "        time2 = int(correct[:2])*60+int(correct[3:])\n",
    "        diff = time2-time1\n",
    "        res = 0\n",
    "        for t in [60,15,5,1]:\n",
    "            res += diff//t\n",
    "            diff %= t\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        t = (int(correct[:2]) * 60 + int(correct[3:])) - (int(current[:2]) * 60 + int(current[3:]))\n",
    "        print(t)\n",
    "        ans = 0\n",
    "        for a in [60, 15, 5, 1]:\n",
    "            ans += (n := (t // a))\n",
    "            t = t - n * a\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        h, m = current.split(\":\")\n",
    "        c = int(h) * 60 + int(m)\n",
    "        h, m = correct.split(\":\")\n",
    "        cc = int(h) * 60 + int(m)\n",
    "        diff = cc - c\n",
    "        ans = 0\n",
    "        for i in (60, 15, 5, 1):\n",
    "            ans += diff // i\n",
    "            diff %= i\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        mod=1440\n",
    "        gap=(int(correct[:2])-int(current[:2]))*60+(int(correct[3:])-int(current[3:]))\n",
    "        ans=0\n",
    "        if gap<0:\n",
    "            gap=1440-gap\n",
    "        while gap:\n",
    "            if gap>=60:\n",
    "                ans+=gap//60\n",
    "                gap=gap%60\n",
    "            elif gap>=15:\n",
    "                ans+=gap//15\n",
    "                gap=gap%15\n",
    "            elif gap>=5:\n",
    "                ans+=gap//5\n",
    "                gap=gap%5\n",
    "            else:\n",
    "                ans+=gap\n",
    "                gap=0\n",
    "        return ans\n",
    "        \n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        def trans(time):\n",
    "            hour = int(time[:2])\n",
    "            minute = int(time[3:])\n",
    "            return hour * 60 + minute\n",
    "        \n",
    "        current = trans(current)\n",
    "        correct = trans(correct)\n",
    "        \n",
    "        d = correct - current\n",
    "        \n",
    "        cnt = 0\n",
    "        cnt += d // 60\n",
    "        d %= 60\n",
    "        cnt += d // 15\n",
    "        d %= 15\n",
    "        cnt += d // 5\n",
    "        d %= 5\n",
    "        cnt += d\n",
    "        \n",
    "        return cnt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        current,correct=current.split(\":\"),correct.split(\":\")\n",
    "        times=0\n",
    "        need=int(correct[0])*60+int(correct[1])-int(current[0])*60-int(current[1])\n",
    "        while need>0:\n",
    "            if need-60>=0:\n",
    "                need-=60\n",
    "            elif need-15>=0:\n",
    "                need-=15\n",
    "            elif need-5>=0:\n",
    "                need-=5\n",
    "            else:\n",
    "                need-=1\n",
    "            times+=1\n",
    "        return times"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        current=datetime.datetime.strptime(current, \"%H:%M\")\n",
    "        correct=datetime.datetime.strptime(correct, \"%H:%M\")\n",
    "        diff=(correct-current).total_seconds()/60\n",
    "        res=0\n",
    "        if diff>=60:\n",
    "            res+=(diff//60)\n",
    "            diff=diff%60\n",
    "        if diff>=15:\n",
    "            res+=(diff//15)\n",
    "            diff=diff%15\n",
    "        if diff>=5:\n",
    "            res+=(diff//5)\n",
    "            diff=diff%5\n",
    "        return int(res+diff)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        current,correct=current.split(\":\"),correct.split(\":\")\n",
    "        times=0\n",
    "        need=int(correct[0])*60+int(correct[1])-int(current[0])*60-int(current[1])\n",
    "        while need>0:\n",
    "            if need-60>=0:\n",
    "                need-=60\n",
    "            elif need-15>=0:\n",
    "                need-=15\n",
    "            elif need-5>=0:\n",
    "                need-=5\n",
    "            else:\n",
    "                need-=1\n",
    "            times+=1\n",
    "        return times"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        current,correct=current.split(\":\"),correct.split(\":\")\n",
    "        times=0\n",
    "        need=int(correct[0])*60+int(correct[1])-int(current[0])*60-int(current[1])\n",
    "        while need>0:\n",
    "            if need-60>=0:\n",
    "                need-=60\n",
    "            elif need-15>=0:\n",
    "                need-=15\n",
    "            elif need-5>=0:\n",
    "                need-=5\n",
    "            else:\n",
    "                need-=1\n",
    "            times+=1\n",
    "        return times"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        count=0\n",
    "        cr=[int(i) for i in current.split(\":\")]\n",
    "        ct=[int(i) for i in correct.split(\":\")]\n",
    "        count+=ct[0]-cr[0]\n",
    "        dmin=ct[1]-cr[1]\n",
    "        #print(count,dmin)\n",
    "        if dmin<0:\n",
    "            count-=1\n",
    "            dmin=dmin+60\n",
    "        #print(count,dmin)\n",
    "        count+=dmin//15\n",
    "        count+=dmin%15//5\n",
    "        count+=dmin%15%5\n",
    "        return count\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        res = 0\n",
    "        a = int(correct[3:]) - int(current[3:]) + (int(correct[:2]) - int(current[:2]))*60\n",
    "        res += a // 60\n",
    "        a %= 60\n",
    "        res += a // 15\n",
    "        a %= 15\n",
    "        res += a // 5\n",
    "        a %= 5\n",
    "        res += a\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        s = current.split(':')\n",
    "        e = correct.split(':')\n",
    "        h = int(e[0]) - int(s[0])\n",
    "        m = int(e[1]) - int(s[1])\n",
    "        if m < 0:\n",
    "            h = h - 1\n",
    "            m = m + 60\n",
    "        a1, b1 = m // 15 , m % 15\n",
    "        a2, b2 = b1 // 5, b1 % 5\n",
    "        return h + a1 + a2 + b2\n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        def f(x):\n",
    "            ans = 0\n",
    "            ans += 60 * int(x[:2]) + int(x[3:])\n",
    "            return ans\n",
    "        diff = f(correct) - f(current)\n",
    "        ans = 0\n",
    "        ans += diff // 60 + (diff % 60) // 15 + (diff % 15) // 5 + (diff % 5)\n",
    "        return ans"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        diff = (int(correct[:2]) - int(current[:2])) * 60 + int(correct[3:]) - int(current[3:])\n",
    "        return diff // 60 + (diff % 60) // 15 + (diff % 15) // 5 + (diff % 5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        res = 0\n",
    "        current0 = int(current[0:2]) * 60 + int(current[3:5])\n",
    "        correct0 = int(correct[0:2]) * 60 + int(correct[3:5])\n",
    "        total = correct0 - current0\n",
    "        res += (total//60 + total%60//15 + total%60%15//5 + total%60%15%5)\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        a,b=current.split(':'),correct.split(':')\n",
    "        a,b=int(a[0])*60+int(a[1]),int(b[0])*60+int(b[1])\n",
    "        a,b=b-a,0\n",
    "        a,b=a%60,a//60\n",
    "        a,b=a%15,b+a//15\n",
    "        return b+a//5+a%5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        time1 = int(current[:2])*60 + int(current[3:])\n",
    "        time2 = int(correct[:2])*60 + int(correct[3:])\n",
    "        diff = time2-time1\n",
    "        res = 0\n",
    "        for t in [60,15,5,1]:\n",
    "            res += diff//t\n",
    "            diff %= t\n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        curr_h,curr_m = int(current.split(':')[0]),int(current.split(':')[1])\n",
    "        unix_curr = curr_h * 60 + curr_m\n",
    "        \n",
    "        corr_h,corr_m = int(correct.split(':')[0]),int(correct.split(':')[1])\n",
    "        unix_corr = corr_h * 60 + corr_m\n",
    "        \n",
    "        # print(unix_curr,unix_corr)\n",
    "        diff = unix_corr - unix_curr\n",
    "        num1,remain1 = diff // 60, diff % 60\n",
    "        num2,remain2 = remain1 // 15, remain1 % 15\n",
    "        num3,remain3 = remain2 // 5, remain2 % 5\n",
    "        res = num1 + num2 + num3 + remain3\n",
    "        return res\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "# class Solution:\n",
    "#     def convertTime(self, current: str, correct: str) -> int:\n",
    "#         mod=1440\n",
    "#         gap=(int(correct[:2])-int(current[:2]))*60+(int(correct[3:])-int(current[3:]))\n",
    "#         ans=0\n",
    "#         # if gap<0: ### 本题不存在current>correct，无需此判断\n",
    "#         #     gap=1440-gap\n",
    "#         while gap:\n",
    "#             if gap>=60:\n",
    "#                 ans+=gap//60\n",
    "#                 gap=gap%60\n",
    "#             elif gap>=15:\n",
    "#                 ans+=gap//15\n",
    "#                 gap=gap%15\n",
    "#             elif gap>=5:\n",
    "#                 ans+=gap//5\n",
    "#                 gap=gap%5\n",
    "#             else:\n",
    "#                 ans+=gap\n",
    "#                 gap=0\n",
    "#         return ans\n",
    "        \n",
    "\n",
    "### 官码：\n",
    "class Solution:\n",
    "    def convertTime(self,current,correct):\n",
    "        time1=int(current[:2])*60+int(current[3:])\n",
    "        time2=int(correct[:2])*60+int(correct[3:])\n",
    "        diff=time2-time1\n",
    "        res=0\n",
    "        for t in [60,15,5,1]:\n",
    "            res+=diff//t \n",
    "            diff%=t   \n",
    "        return res"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\n",
    "    def convertTime(self, current: str, correct: str) -> int:\n",
    "        current=current.split(':')\n",
    "        correct=correct.split(\":\")\n",
    "        current1=int(current[0])\n",
    "        current2=int(current[1])\n",
    "        correct1=int(correct[0])\n",
    "        correct2=int(correct[1])\n",
    "        diff=(current1-correct1)*60+(current2-correct2)\n",
    "        count=0\n",
    "        diff=abs(diff)\n",
    "        if diff>=60:\n",
    "            count+=diff//60\n",
    "            diff=diff%60\n",
    "        \n",
    "        if diff>=15:\n",
    "            count+=diff//15\n",
    "            diff=diff%15\n",
    "        \n",
    "        if diff>=5:\n",
    "            count+=diff//5\n",
    "            diff=diff%5\n",
    "        \n",
    "        if diff>=1:\n",
    "            count+=diff//1\n",
    "            diff=diff%1\n",
    "        \n",
    "        return count\n",
    "        \n",
    "        \n",
    "\n",
    "        \n",
    "        \n",
    "            \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "from typing import List\n",
    "import collections\n",
    "\n",
    "class Solution:\r\n",
    "    def convertTime(self, current: str, correct: str) -> int:\r\n",
    "        def cal(time):\r\n",
    "            return int(time[:2]) * 60 + int(time[3:])\r\n",
    "        def help(be, tar, v):\r\n",
    "            res = 0\r\n",
    "            while be + v <= tar:\r\n",
    "                res += 1\r\n",
    "                be += v\r\n",
    "            return [res, be]\r\n",
    "        a, b = cal(current), cal(correct)\r\n",
    "        print(a, b)\r\n",
    "        res1, a = help(a, b, 60)\r\n",
    "        print(a, b)\r\n",
    "        res2, a = help(a, b, 15)\r\n",
    "        print(a, b)\r\n",
    "        res3, a = help(a, b, 5)\r\n",
    "        print(a, b)\r\n",
    "        res4, a = help(a, b, 1)\r\n",
    "        print(a, b)\r\n",
    "        return res1 + res2 + res3 + res4"
   ]
  }
 ],
 "metadata": {},
 "nbformat": 4,
 "nbformat_minor": 2
}
